package com.zyg.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zyg.pojo.Hotel;
import com.zyg.pojo.Major;
import com.zyg.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.List;

public interface StudentMapper extends BaseMapper<Student> {
    @Override
    @Select("select s_id,student_num,student_name,gender,age,date_of_birth,class_id,hotel_id,phone,email,home_address,emergency_contact,emergency_contact_phone,major,status,remark from student_info  ${ew.customSqlSegment}")
    @Results({
            @Result(property = "sid",column = "s_id"),
            @Result(property = "studentNum",column = "student_num"),
            @Result(property = "studentName",column = "student_name"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "age",column = "age"),
            @Result(property = "birthday",column = "date_of_birth"),
            @Result(property = "cla",column = "class_id",javaType = Class.class,
                    one = @One(select = "com.zyg.dao.ClassMapper.selectById")),
            @Result(property = "hotel",column = "hotel_id",javaType = Hotel.class,
                    one = @One(select = "com.zyg.dao.HotelMapper.selectById")),
            @Result(property = "phone",column = "phone"),
            @Result(property = "email",column = "email"),
            @Result(property = "homeAddress",column = "home_address"),
            @Result(property = "emergencyContact",column = "emergency_contact"),
            @Result(property = "emergencyContactPhone",column = "emergency_contact_phone"),
            @Result(property = "maj",column = "major",javaType = Major.class,
                    one = @One(select = "com.zyg.dao.MajorMapper.selectById")),
            @Result(property = "status",column = "status"),
            @Result(property = "remark",column = "remark"),
    })
    List<Student> selectList(IPage<Student> page, @Param(Constants.WRAPPER) Wrapper<Student> queryWrapper);

    @Override
    @Update("UPDATE student_info  SET del_flag = 1 WHERE s_id = #{id}")
    default int deleteById(Serializable id) {
        // 逻辑删除
        return update(Wrappers.<Student>update().eq("s_id", id).set("del_flag", 1));
    }
}
